package 富婆梦.第一阶段.第七周IO流;

import java.nio.ByteBuffer;

import static sun.misc.Version.print;

/**
 * @ProjectName: java-learning
 * @Package: 富婆梦.第一阶段.第七周
 * @ClassName: GetData
 * @Author: hemengjin
 * @Description: nio缓冲器ByteBuffer：获得基本类型
 * @Date:2021/9/12 22:31
 * @Version: 1.0
 */
public class GetData {
    private static final int BSIZE = 1024;

    public static void main(String[] args) {
        ByteBuffer bb = ByteBuffer.allocate(BSIZE);
        int i=0;
        while (i++<bb.limit()){
            if (bb.get()!=0){
                System.out.println("nonzero");
            }
        }
        System.out.println("i="+i);
        bb.rewind();
        bb.asCharBuffer().put("Howdy!");
        char c;
        while ((c=bb.getChar())!=0)
            System.out.println(c+" ");
        print();
        bb.rewind();
        bb.asShortBuffer().put((short)471142);
        System.out.println(bb.getShort());
        bb.rewind();
        bb.asIntBuffer().put(99471142);
        System.out.println(bb.getInt());
        bb.rewind();
        bb.asLongBuffer().put(99471142);
        System.out.println(bb.getLong());
        bb.rewind();
        bb.asFloatBuffer().put(99471142);
        System.out.println(bb.getFloat());
        bb.rewind();
        bb.asDoubleBuffer().put(99471142);
        System.out.println(bb.getDouble());
    }
}
